#include <bits/stdc++.h>

using namespace std;

class Solution {
public:
	void solve(vector<vector<char>>& board)
	{
		int colLen = board.size(), rowLen = board[0].size();
		queue<pair<int, int>> que;

		const int dx[4] = { 1, -1, 0, 0 },
				  dy[4] = { 0, 0, 1, -1 };
		for (int i = 0; i < colLen; i++) {
			if (board[i][0] == 'O') {
				que.emplace(i, 0);
				board[i][0] = 'A';
			}
			if (board[i][rowLen - 1] == 'O') {
				que.emplace(i, rowLen - 1);
				board[i][rowLen - 1] = 'A';
			}
		}
		for (int i = 1; i < rowLen - 1; i++) {
			if (board[0][i] == 'O') {
				que.emplace(0, i);
				board[0][i] = 'A';
			}
			if (board[colLen - 1][i] == 'O') {
				que.emplace(colLen - 1, i);
				board[colLen - 1][i] = 'A';
			}
		}

		while (!que.empty()) {
			auto pop = que.front();
			que.pop();

			int col = pop.first, row = pop.second;
			for (int i = 0; i < 4; i++) {
				int mx = col + dx[i], my = row + dy[i];
				if (mx < 0 || mx >= colLen || my < 0 || my >= rowLen || board[mx][my] != 'O')
					continue;
				que.emplace(mx, my);
				board[mx][my] = 'A';
			}
		}

		for (int i = 0; i < colLen; i++) {
			for (int j = 0; j < rowLen; j++)
				cout << board[i][j] << "\t";
			cout << "\n";
		}

		for (int i = 0; i < colLen; i++) {
			for (int j = 0; j < rowLen; j++) {
				char& point = board[i][j];
				if (point == 'A')
					point = 'O';
				else if (point == 'O')
					point = 'X';
			}
		}
	}
};

int main()
{
	Solution solu;
	vector<vector<char>> board = { { 'O' } };
	solu.solve(board);
	return 0;
}
